package jm.data.structure.leet_code;

 
/**
 * @Description https://leetcode-cn.com/problems/delete-node-in-a-linked-list/
 * @date 2022/4/5 17:11
 */
public class _237删除链表中的节点 {
    public static void main(String[] args) {
        ListNode listNode = new ListNode(1);
        ListNode listNode1 = new ListNode(2);
        ListNode listNode2 = new ListNode(12);
        ListNode listNode3 = new ListNode(3);

        listNode.next = listNode1;
        listNode1.next = listNode2;
        listNode2.next = listNode3;

        deleteNode(listNode2);

        ListNode node = listNode;

        while (node != null){
            System.out.println(node.val);
            node = node.next;
        }
    }

    public static void deleteNode(ListNode node) {
        node.val = node.next.val;
        node.next = node.next.next;
    }
    static class ListNode{
        int val;
        ListNode next;
        ListNode(int x) {
            this.val = x;
            this.next = null;
        }
        ListNode(int x, ListNode next) {
            this.val = x;
            this.next = next;
        }
    }
}



